<!--
  ~ This program is part of the OpenLMIS logistics management information system platform software.
  ~ Copyright © 2013 VillageReach
  ~
  ~ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  ~  
  ~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
  ~ You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
  -->

<div ng-controller="ApproveFullSupplyController">

  <div id="pageErrors" class="page-errors" ng-show="errorPages.fullSupply">
    <div ng-switch on="errorPages.fullSupply.length" class="dropdown">
      <a href="" ng-switch-when="1" class="dropdown-toggle" openlmis-message="error.one.page"></a>
      <a href="" ng-switch-default class="dropdown-toggle"
         openlmis-message="error.multiple.pages|fullSupplyErrorPagesCount"></a>
      <ul class="dropdown-menu">
        <li ng-repeat="page in errorPages.fullSupply">
          <a href="" ng-click="goToPage(page, $event)">{{page}}</a>
        </li>
      </ul>
    </div>

  </div>

  <div ng-hide="page.fullSupply.length" class="alert alert-info" openlmis-message="label.no.products"></div>

  <div id="approveRnr" class="rnr-table rnr-approval" custom-horizontal-scroll adjust-height>
    <div class="float-left left-table">
      <table id="fullSupplyFrozenTable" fixed-table-header class="table table-bordered scrollable">
        <thead>
        <tr>
          <th class="col-{{column.name}}" ng-repeat="column in visibleColumns.fullSupply.fixed"
              ng-bind="column.label"></th>
        </tr>
        </thead>
        <tbody ng-repeat="rnrLineItem in page.fullSupply">
        <tr>
          <td class="productCategory" colspan="{{visibleColumns.fullSupply.fixed.length}}"
              ng-show="showCategory($index)"
              ng-bind="rnrLineItem.productCategory"></td>
        </tr>
        <tr>
          <td class="cell-input col-{{ column.name }}" ng-repeat="column in visibleColumns.fullSupply.fixed">
            <span ng-switch on="column.name">
              <span ng-switch-when="skipped">
                <input ng-model="rnrLineItem[column.name]" id="skip_{{$parent.$parent.$index}}"
                       ng-disabled="(!rnrLineItem.canSkip() && !rnrLineItem[column.name])" type="checkbox">
              </span>
              <span ng-switch-default ng-bind="rnrLineItem[column.name]" id="{{getId(column.name, $parent)}}"
                    class="cell-text"></span>
            </span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <div class="float-left right-table" custom-horizontal-scroll>
      <table id="fullSupplyTable" fixed-table-header class="table table-bordered scrollable">
        <thead>
        <tr>
          <th class="col-{{column.name}}" ng-repeat="column in visibleColumns.fullSupply.scrollable"
              ng-bind="column.label"></th>
        </tr>
        </thead>
        <tbody ng-repeat="rnrLineItem in page.fullSupply">
        <tr>
          <td class="productCategory" colspan="{{visibleColumns.fullSupply.scrollable.length}}"
              ng-show="showCategory($index)"></td>
        </tr>
        <tr>
          <td class="cell-input col-{{ column.name }}"
              ng-repeat="column in visibleColumns.fullSupply.scrollable">
            <span ng-switch on="column.name">
              <span ng-switch-when="lossesAndAdjustments">
                <div>
                  <a id="showLossesAdjustment" href="" ng-click="showLossesAndAdjustments(rnrLineItem)"
                     class="rnr-adjustment">
                    <span ng-bind="rnrLineItem.totalLossesAndAdjustments" class="adjustment-value"></span>
                  </a>
                </div>
              </span>

              <span ng-switch-when="quantityApproved" class="position-relative">
                <input ng-change='rnr.fillPacksToShip(rnrLineItem)' ng-required="true" type="text"
                       ng-model="rnrLineItem[column.name]" numeric-validator="positiveInteger" maxlength="8"
                       name="quantityApproved{{$parent.$parent.$index}}" ng-disabled="rnrLineItem['skipped']"
                       id="{{getId(column.name, $parent)}}" ng-trim="false"
                       ng-class="highlightRequired(approvedQuantityRequiredFlag, rnrLineItem[column.name], rnrLineItem.skipped)"/>
                <span class="rnr-form-error" id="quantityApproved{{$parent.$parent.$index}}"
                      style="display:none;" openlmis-message="error.number.only"></span>
              </span>

              <span ng-switch-when="remarks">
                <input id="{{getId(column.name, $parent)}}" type="text"
                       name="remarks{{rnrLineItem['id']}}"
                       ng-model="rnrLineItem[column.name]"
                       ng-disabled="rnrLineItem['skipped']"
                       maxlength="250"/>
              </span>

              <span ng-switch-when="price">
                <span ng-bind='rnrLineItem[column.name] | currency:currency' id="{{getId(column.name, $parent)}}"
                      class="cell-text"></span>
              </span>

              <span ng-switch-when="cost">
                <span ng-bind='rnrLineItem[column.name] | currency:currency' id="{{getId(column.name, $parent)}}"
                      class="cell-text"></span>
              </span>

              <span ng-switch-default ng-bind="rnrLineItem[column.name]" id="{{getId(column.name, $parent)}}"
                    class="cell-text"></span>
            </span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <div class="clear-both"></div>
  </div>

  <ng-include src="'/public/pages/logistics/rnr/partials/approve/losses-and-adjustments.html'"></ng-include>
</div>